package textdiff {
	import mx.collections.ArrayCollection;
	

	/**
	 * A block of matching lines is either a "match" for no edit required,
	 * or "move" for blocks that changed order.
	 */
	public class MatchCommand extends EditCommand {
	    public function MatchCommand(oldFileInfo:FileInfo=null, newFileInfo:FileInfo=null) {
	        super( oldFileInfo, newFileInfo );
	        if (oldFileInfo != null && newFileInfo != null) {
		        var oldLineInfo: LineInfo = oldFileInfo.currentLineInfo();
		        var newLineInfo: LineInfo = newFileInfo.currentLineInfo();
		        if (oldLineInfo.newLineNum == newFileInfo.lineNum)
		        {
		            command = "Match";
		            newLines = newFileInfo.nextBlock();
		        }
		        else
		        {
		            command = "Move";
		            newLines = newFileInfo.getBlockAt( oldLineInfo.newLineNum );
		        }
		        oldLines = oldFileInfo.nextBlock();
		        oldLines.reportable = true;
		        newLines.reportable = false;
		    }
	    }

	    public override function toEditScript(): String {
			var s:String = ""+oldLines.fromLineNum;
	    	if (oldLines.fromLineNum < oldLines.thruLineNum) {
	    		s += "," + oldLines.thruLineNum;
	    	} 
	    	s += "d\r.\r";
	    	s += newLines.fromLineNum + "i\r" + newLines.textLines + ".\r";
	    	return s;

	    }

	    public override function get fromLineNum(): int { return oldLines.fromLineNum; }
	    public override function get thruLineNum(): int { return oldLines.thruLineNum; }
	}

}
